Primitive Roots
Introduction
Primitive roots are special integers that behave like “engines” inside modular arithmetic.
For a prime $p$, a primitive root is an integer that can produce every nonzero number modulo $p$ just by taking powers.
Key ideas to keep in mind:
- We work modulo a prime $p$.
- We only look at the nonzero residues $1,2,\dots,p-1$.
- A primitive root is an integer whose powers cycle through all of these residues.
Why Primitive Roots Matter
Primitive roots matter because they reveal a hidden structure:
- The nonzero numbers modulo $p$ behave like a multiplicative group.
- A primitive root is like a “generator” of this group.
- Many number‑theoretic algorithms rely on primitive roots:
- Diffie–Hellman key exchange
- Discrete logarithms
- Pseudorandom number generation
- They give a compact way to describe all nonzero residues:
- Instead of listing $1,2,\dots,p-1$, you can list powers of a single number.
Primitive roots turn modular arithmetic into something more predictable and algebraic.
The Multiplicative World Modulo $p$
When $p$ is prime:
- Every nonzero integer modulo $p$ has a multiplicative inverse.
- The set $$\{1,2,\dots,p-1\}$$ forms a group under multiplication modulo $p$.
- This group has exactly $p-1$ elements.
Important facts:
- Multiplying two nonzero residues gives another nonzero residue.
- Repeated multiplication (powers) stays inside this set.
- The structure is cyclic — meaning it has a generator — and that generator is a primitive root.
What It Means to “Generate” All Nonzero Residues
To “generate” all nonzero residues means:
- Start with some integer $g$.
- Compute $$g^1, g^2, g^3, \dots \pmod p.$$
- If these powers eventually produce every number from $1$ to $p-1$, then $g$ is a primitive root.
In other words:
- The powers of $g$ “walk through” the entire multiplicative world modulo $p$.
- No repeats until you’ve seen all residues.
This is similar to how:
- $1, 2, 4, 8, 16, \dots$ cycles through powers of $2$ in ordinary arithmetic.
- But modulo $p$, the cycle wraps around and can cover everything.
Definition of a Primitive Root (Using Order)
For a prime $p$:
- The order of $g$ modulo $p$ is the smallest positive integer $k$ such that $$g^k \equiv 1 \pmod p.$$
Definition:
An integer $g$ is a primitive root modulo $p$ if its order is exactly $p-1$.
Why $p-1$?
- Because there are $p-1$ nonzero residues.
- If the order is $p-1$, the powers of $g$ must hit all of them.
Small Examples to Build Intuition
Example 1: Primitive roots modulo $7$
Compute powers of $3$:
- $3^1 \equiv 3$
- $3^2 \equiv 2$
- $3^3 \equiv 6$
- $3^4 \equiv 4$
- $3^5 \equiv 5$
- $3^6 \equiv 1$
We saw all residues $1$–$6$, so $3$ is a primitive root mod $7$.
Example 2: A non‑example
Try $2$ modulo $7$:
- $2^1 \equiv 2$
- $2^2 \equiv 4$
- $2^3 \equiv 1$
The order is $3$, not $6$, so $2$ is not a primitive root.
How Many Primitive Roots Does a Prime Have?
A prime $p$ always has primitive roots — in fact, more than one.
Facts:
- The number of primitive roots modulo $p$ is $\varphi(p-1)$.
- Here $\varphi$ is Euler’s totient function.
- Example:
- For $p=7$, $p-1=6$, and $\varphi(6)=2$.
- The primitive roots mod $7$ are $3$ and $5$.
Interpretation:
- Primitive roots are not rare.
- But they are “special” — only a fraction of numbers have full order.
Testing Whether an Integer Is a Primitive Root (Practical Method)
To test whether $g$ is a primitive root modulo $p$:
- Factor $p-1$ into primes: $$p-1 = q_1^{e_1} q_2^{e_2} \cdots q_k^{e_k}.$$
- For each distinct prime factor $q_i$, compute $$g^{(p-1)/q_i} \pmod p.$$
- If none of these values is $1$, then $g$ is a primitive root.
Why this works:
- If $g$ had smaller order, that order would divide $p-1$.
- One of these exponent tests would reveal it.
This is the standard practical test used in cryptography.
Note
- This test applies when $p$ is prime
- because in that case the multiplicative group modulo $p$ is cyclic of order $p-1$.
- For general moduli $n$, the analogous test uses $\varphi(n)$ instead of $p-1$,
- and primitive roots exist only for $n = 1, 2, 4, p^k, 2p^k$ with $p$ odd prime.
Finding Primitive Roots Efficiently
Strategies:
- Trial and error with the test above.
- Start with small integers: $2,3,4,\dots$.
- For many primes, $2$ or $3$ is already a primitive root.
- Use the fact that:
- If $g$ is a primitive root, then $g^k$ is also a primitive root iff $\gcd(k,p-1)=1$.
Tips for beginners:
- Always factor $p-1$ first.
- Keep a small table of powers to avoid recomputing.
- Use modular exponentiation to speed things up.
Which Numbers Have Primitive Roots?
Primitive roots do not exist for every modulus.
They exist for all primes, but only for certain composite numbers.
This section gives a simple, memorable rule your readers can rely on.
The Complete Classification
A modulus $ n $ has primitive roots if and only if it is one of the following types:
- $n = 2$
- $n = 4$
- $n = p^k$ where $p$ is an odd prime
- $n = 2p^k$ where $p$ is an odd prime
Why This Matters
Primitive roots are generators of the multiplicative group modulo $n$.
That group is cyclic only for the moduli listed above.
So:
- If the multiplicative group modulo $n$ is cyclic → primitive roots exist.
- If the group is not cyclic → primitive roots do not exist.
This is a deep theorem, but the classification itself is easy to use.
Examples of Moduli That Have Primitive Roots
Powers of odd primes
- $3, 9, 27, 81, \dots$
- $5, 25, 125, \dots$
- $7, 49, 343, \dots$
Twice a power of an odd prime
- $2\cdot 3 = 6$
- $2\cdot 3^2 = 18$
- $2\cdot 5 = 10$
- $2\cdot 5^2 = 50$
The special small cases
All of these have primitive roots.
Examples of Moduli That Do Not Have Primitive Roots
These fail the classification:
- Any modulus with two different odd prime factors
- e.g., $15 = 3\cdot 5$, $21 = 3\cdot 7$, $33 = 3\cdot 11$
- Any modulus divisible by $8$
- e.g., $8, 16, 24, 40, 72$
- Any modulus of the form
- $4p$ where $p$ is odd
- e.g., $12, 20, 28, 44$
These moduli have multiplicative groups that are not cyclic, so primitive roots cannot exist.
Applications in Cryptography and Randomness
Primitive roots appear in many modern algorithms:
Cryptography
- Diffie–Hellman key exchange uses a primitive root $g$ modulo a large prime $p$.
- Discrete logarithm problem relies on the difficulty of solving $$g^x \equiv h \pmod p.$$
Randomness and pseudorandom generators
- Some generators use powers of a primitive root to produce sequences that “look random”.
Number theory
- They simplify proofs about modular arithmetic.
- They allow us to express every nonzero residue as a power of a single number.
Common Mistakes and Misunderstandings
Beginners often stumble on:
- Confusing “order” with “primitive root”
- Order is a property of any integer.
- Primitive roots are those with maximum order.
- Thinking primitive roots exist for all moduli
- They exist for primes and for certain special composite numbers, but not all.
- Forgetting to check *all* prime factors of $p-1$
- Missing even one factor can give a false positive.
- Assuming $g$ must be small
- Any residue could be a primitive root.
Summary and Key Ideas
- The nonzero residues modulo a prime form a multiplicative group of size $p-1$.
- A primitive root is an integer whose powers generate all these residues.
- The order of a primitive root is exactly $p-1$.
- Primitive roots always exist for primes.
- They are essential in modern cryptography and many number‑theoretic algorithms.
Calculator
Modular Exponents
- Calculates $a^b \pmod{m}$
modPow(a, b, m) modPow(3, 6, 7)
Primitive Roots
- Returns the primitive roots
primitiveRoots(13) primitiveRoots(38)
Exercises
- Compute powers: List the powers of $3$ modulo $11$ until they repeat.
Does $3$ generate all nonzero residues? - Find a primitive root: Find at least one primitive root modulo $13$.
- Test a candidate: Determine whether $2$ is a primitive root modulo $17$.
- Count primitive roots: How many primitive roots does $p=19$ have?
(Hint: compute $\varphi(18)$.) - Order practice: Find the order of $4$ modulo $11$.
Is it a primitive root? - Factor‑based test: Use the prime factorization of $p-1$ to test whether $6$ is a primitive root modulo $13$.
- Challenge: Show that if $g$ is a primitive root modulo $p$, then $g^k$ is also a primitive root iff $\gcd(k,p-1)=1$.
- Application question: Explain why primitive roots are useful in cryptography.